package com.yiyuan.app.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.guaike.core.mybatis.plugins.BaseDAO;
import com.yiyuan.app.entity.po.MRankRichPO;
import com.yiyuan.app.mapper.MRankRichMapper;
import org.springframework.stereotype.Repository;

import java.time.LocalDate;
import java.util.List;

@Repository
public class MRankRichDAO extends BaseDAO<MRankRichMapper, MRankRichPO> {


    public List<MRankRichPO> findTodayRankList(LocalDate today, Integer size) {
        LambdaQueryWrapper<MRankRichPO> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(MRankRichPO::getRankDate, today);
        queryWrapper.orderByDesc(MRankRichPO::getRechargeMoney);
        queryWrapper.last("limit 0," + size);
        return getBaseMapper().selectList(queryWrapper);
    }

    public List<MRankRichPO> findYesRankList(LocalDate yesterday) {
        LambdaQueryWrapper<MRankRichPO> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(MRankRichPO::getRankDate, yesterday);
        queryWrapper.eq(MRankRichPO::getIsRank, Boolean.TRUE);
        queryWrapper.orderByAsc(MRankRichPO::getRankNo);
        return getBaseMapper().selectList(queryWrapper);
    }

    public MRankRichPO findUserRank(LocalDate today, Long userId) {
        LambdaQueryWrapper<MRankRichPO> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(MRankRichPO::getRankDate, today);
        queryWrapper.eq(MRankRichPO::getUserId, userId);
        return getBaseMapper().selectOne(queryWrapper);
    }
}
